import React from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import styles from './index.module.scss';
import { NavBar, Icon } from 'antd-mobile';

console.log(styles)

class TitleHeader extends React.Component {
  static propTypes = {
    title: PropTypes.string.isRequired,
    onLeftClick: PropTypes.func
  }

  onLeftClick = () => {
    if(this.props.onLeftClick) {
      return this.props.onLeftClick();
    }

    this.props.history.go(-1);
  }

  render() {
    return (
      <NavBar
        mode="light"
        icon={<Icon type="left" />}
        onLeftClick={this.onLeftClick}
      >
        {this.props.title}
      </NavBar>
    )
  }
}

export default withRouter(TitleHeader)